home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 / IRIX 6.2 CD1.iso / coffcheck < prev    next >
Text File  |  1996-06-11  |  8KB  |  261 lines

  1. #!/bin/ksh -p
  2. #       The flag is:
  3. #           -p privileged (skips . $ENV)
  4.  
  5. # coffcheck
  6. # Use: "coffcheck -help" for help.
  7. #
  8. # Finds COFF executable files on local file systems.
  9. # Useful when upgrading to IRIX 6.2, which no longer supports COFF.
  10. #
  11. # Best to run as root, to avoid errors due to unreadable files or directories.
  12. #
  13. # Does a "find" command over all local file systems -- could take a while
  14. # on systems with large local disk storage.
  15. #
  16. # Input:
  17. #   Your local file systems and inst history.
  18. #
  19. # Output:
  20. #   /usr/tmp/Coff.files.list:
  21. #        List of executable COFF files found on local file systems.
  22. #        (Files known to be installed using inst are intentionally
  23. #        excluded from this list -- see the next list.)
  24. #   /usr/tmp/Coff.inst_subsystems.list:
  25. #        List of inst subsystems that contain one more currently
  26. #        installed executable COFF files.  These subsystems should
  27. #        be removed or upgraded when IRIX 6.2 is installed.
  28. #   /usr/tmp/Coff.errs:
  29. #        Error output produced by this script's internals.
  30. #
  31. #   The above files are not produced if their output would be empty.
  32.  
  33.  
  34. #########
  35. # Step 1:
  36. #   Establish a safe environment and temporary workarea in /usr/tmp/coffcheck.$$
  37.  
  38. export TMPDIR=${TMPDIR:=/usr/tmp}
  39. export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/bsd:/etc:/usr/etc
  40.  
  41. # Where output list and errors go, if not empty.
  42.  
  43. coff_file_list=$TMPDIR/Coff.files.list
  44. coff_subsys_list=$TMPDIR/Coff.inst_subsystems.list
  45. errlist=$TMPDIR/Coff.errs
  46.  
  47. if [ $# -gt 0 ] # help
  48. then echo '
  49. This command accepts no options.  It checks all files on your
  50. local filesystems for COFF executable programs.  This is the
  51. object file format from IRIX 4.0.5 and earlier releases.
  52. These programs will no longer execute under IRIX 6.2 and later
  53. IRIX releases.
  54.  
  55. This program will create two output files, containing a list of
  56. subsystems installed with "inst" that contain COFF executables
  57. (so you know which subsystems must be upgraded to be fully
  58. functional under IRIX 6.2 ), and also a list of COFF executables
  59. on your system that do not appear to have been installed by
  60. "inst".  Such programs are either locally built, copied from
  61. other systems, or part of third party packages.  You will need to
  62. build or otherwise get replacements for these programs, if you
  63. will need the functions that they provide, once you have upgraded
  64. to IRIX 6.2.  The default names of these output files are
  65. '$coff_subsys_list and $coff_file_list',
  66. respectively.
  67.  
  68. If you are currently running irix 4.0.x, almost all substems
  69. installed by "inst" will be listed.  A few subsystems shipped
  70. with IRIX 5 and IRIX 6.0.1 and 6.1 still contain COFF executables
  71. also.
  72. '
  73. exit 0
  74. fi
  75.  
  76. if test ! -w /etc/passwd
  77. then
  78.     echo You do not appear to be running this as super user.
  79.     echo Some errors may occur due to unreadable files or directories as a result.\\n
  80. fi
  81.  
  82. tmpdir=$TMPDIR/coffcheck.$$
  83. exitval=1
  84. trap 'cd /; exec 2>&1; fuser -kq $tmpdir $tmpdir/coffcheck.errs; rm -fr $tmpdir; trap 0; exit $exitval' 0 1 2 3 15
  85. mkdir $tmpdir
  86.  
  87. cd $tmpdir    # Create tmp files in this temporary directory
  88.  
  89. exec 2>coffcheck.errs
  90.  
  91. #########
  92. # Step 2:
  93. #   If someone under a different uid has already run this script,
  94. #   we won't be able to write the output files -- add a unique
  95. #   numeric suffix so we can write them:
  96.  
  97. mkunique()
  98. {
  99.     (rm -f $1; ls -ld $1) 1>&- 2>&- || {
  100.     eval $2=$1
  101.     return
  102.     }
  103.  
  104.     n=1
  105.     while (rm -f $1.$n; ls -ld $1.$n) 1>&- 2>&-
  106.     do
  107.     let n=n+1
  108.     done
  109.     eval $2=$1.$n
  110. }
  111.  
  112. mkunique $coff_file_list coff_file_list
  113. mkunique $coff_subsys_list coff_subsys_list
  114. mkunique $errlist errlist
  115.  
  116. #########
  117. # Step 3:
  118. #   Find all COFF files on local file systems.
  119.  
  120. echo Searching local filesystems for COFF executable files ... '\c'
  121.  
  122. # anything in the /stand and /usr/stand dirs are ommitted, as some of these
  123. # must remain COFF on many systems in order for the PROM to be able to execute
  124. # them.  Similarly with /unix*
  125. # the first sed is in case filenames have embedded spaces or tabs
  126. find / -local -type f \( -perm -100 -o -perm -10 -o -perm -1 \) -print |
  127.     sed 's/[     ]/\\&/g' |
  128.     xargs file |
  129.     egrep 'MIPSEB.*COFF|    mipseb ' |
  130.     sed -e 's/:    .*//' -e '/^\/stand\//d' -e '/^\/usr\/stand/d' -e '/^\/unix/d' |
  131.     sort -u > find.list
  132.  
  133. # The printer GUI files often come in both COFF and ELF forms,
  134. # so IRIX 4 systems can use them also (clients copy them from the
  135. # server).
  136. if grep /var/spool/lp/gui_model find.list > lpgui.list
  137. then # found some lp gui files, don't complain about coff equivalents
  138.     # if ELF versions installed
  139.     sed 's,gui_model/,&ELF/,' lpgui.list | ( while read elf rest; do
  140.         if [ -x "$elf" ]; then echo $elf >> lpgui.elf;
  141.         fi
  142.         done )
  143.     sed s,/ELF/,/, lpgui.elf > lpgui.rem
  144.     if [ -s lpgui.rem ]; then
  145.         fgrep -f lpgui.rem -v find.list > find.nlist && \
  146.             mv find.nlist find.list
  147.     fi
  148. fi
  149.  
  150. echo '\n'Preparing results ... '\c'
  151.  
  152. #########
  153. # Step 4:
  154. #   Compile realpath - used to canonicalize 'versions long' output pathnames.
  155. #   If unable to compile, realpath defaults to a no-op command.
  156. #   A second field is expected on each line, and passed through unchanged.
  157.  
  158. export TOOLROOT=/
  159. [ -d /usr/sysgen/root/usr/bin ] && TOOLROOT=/usr/sysgen/root
  160. [ -d /usr/cpu/sysgen/root/usr/bin ] && TOOLROOT=/usr/cpu/sysgen/root
  161.  
  162. PATH=$TOOLROOT/usr/bin:$PATH
  163.  
  164. cat <<!! > realpath.c
  165.     char buf1[1024], buf2[1024], buf3[1024], buf4[1024];
  166.  
  167.     /*
  168.      * input: two fields per line (1) pathname, (2) string (inst subsys)
  169.      * output: two fields per line (1) realpath of pathname, (2) same string
  170.      */
  171.  
  172.     main()
  173.     {
  174.     while (gets (buf1) != 0) {
  175.         sscanf (buf1, "%s %s", buf2, buf3);
  176.         realpath (buf2, buf4);
  177.         printf ("%s %s\n", buf4, buf3);
  178.     }
  179.     return 0;
  180.     }
  181. !!
  182.  
  183. cc -o realpath realpath.c 2>/dev/null || echo cat > realpath
  184. chmod +x realpath
  185.  
  186. #########
  187. # Step 5:
  188. #   Obtain list of inst'd files from "versions long".
  189. #   Canonicalize these pathnames using realpath.
  190. #   Feed that stream to two command pipes (via two named pipes).
  191. #   The two command pipes calculate (1) the COFF files that
  192. #   weren't installed via inst, and (2) the inst subsystems
  193. #   which have one or more COFF files installed.
  194.  
  195. mknod pipe1 p        # named pipe to feed first command pipe
  196. mknod pipe2 p        # named pipe to feed second command pipe
  197.  
  198. #############
  199. # SubStep 5a:
  200. #   First command pipe.
  201. #   Calculate list of COFF files that were not inst'd.
  202.  
  203. < pipe1 awk '{print $1}' |
  204.     sort -u |
  205.     comm -23 find.list - > coff.file.list &
  206.     
  207. #############
  208. # SubStep 5b:
  209. #   Second command pipe.
  210. #   Calculate list of inst subsystems having one or more COFF files.
  211.  
  212. < pipe2 sort -u |
  213.     join -j 1 -o 1.2 - find.list |
  214.     sort -u > coff.subsys.list &
  215.  
  216. #############
  217. # SubStep 5c:
  218. #   Common source for the two command pipes.
  219. #   Obtain list of inst'd files from "versions long",
  220. #   and feed to the above two command pipes.
  221.  
  222. versions long |
  223.     awk '$1 == "f" {print "/" $NF, $4}' |
  224.     ./realpath |
  225.     tee pipe1 > pipe2
  226.  
  227. wait
  228.  
  229. #########
  230. # Step 6:
  231. #   Present results to user.
  232.  
  233. echo '\n'
  234.  
  235. if [ -s coff.file.list ]
  236. then
  237.     mv coff.file.list $coff_file_list
  238.     echo List of files that won\'t run under IRIX 6.2 is in:
  239.     echo '\t'$coff_file_list
  240. else
  241.     echo There are apparently no files on this system that won\'t run under IRIX 6.2
  242. fi
  243.  
  244. if [ -s coff.subsys.list ]
  245. then
  246.     mv coff.subsys.list $coff_subsys_list
  247.     echo List of inst subsystems containing files that won\'t run under IRIX 6.2 is in:
  248.     echo '\t'$coff_subsys_list
  249. else
  250.     echo There are no inst subsystems containing files that won\'t run under IRIX 6.2
  251. fi
  252.  
  253. if [ -s coffcheck.errs ]
  254. then
  255.     mv coffcheck.errs $errlist
  256.     echo Some errors occurred during check, they are in:
  257.     echo '\t'$errlist
  258. fi
  259.  
  260. exitval=0
  261.